/*  
 * @(#) BaseAction.java Create on 2012-5-8 上午11:57:05   
 *   
 * Copyright 2012 by xl.   
 */

package cn.com.common.base.action;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 
 * @author zhanghongliang
 * @date 2012-5-8
 */
public class BaseAction extends ActionSupport {

	protected Logger logger = Logger.getLogger(this.getClass());
	/*
	 * 跳转到主页面
	 */
	protected final static String TOINDEX = "toIndex";

	/*
	 * 跳转到编辑页面
	 */
	protected final static String TOEDIT = "toEdit";

	/*
	 * 退出系统
	 */
	protected final static String LOGOUT = "logout";

	/*
	 * to 欢迎页面
	 */
	protected final static String TOWELCOME = "toWelcome";

	/*
	 * 没有权限页面
	 */
	protected final static String NOPRIVILEGE = "noPrivilege";

	private static final long serialVersionUID = 263091553793684762L;

	/**
	 * 放入context数据
	 * 
	 * @author zhl
	 * @date 2012-05-08下午02:20:42
	 * 
	 * @param key
	 * @param value
	 */
	protected void putToContext(String key, Object value) {
		ActionContext.getContext().put(key, value);
	}

	/**
	 * 从context中取数据
	 * 
	 * @author zhl
	 * @date 2012-05-08下午02:28:42
	 * 
	 * @param key
	 * @return
	 */
	protected Object getFromContext(String key) {
		return ActionContext.getContext().get(key);
	}

	/**
	 * 放入session数据
	 * 
	 * @author zhl
	 * @date 2012-05-08下午02:20:56
	 * 
	 * @param key
	 * @param value
	 */
	protected void putToSession(String key, Object value) {
		ServletActionContext.getRequest().getSession().setAttribute(key, value);
	}

	/**
	 * 从session中取数据
	 * 
	 * @author zhl
	 * @date 2012-05-08下午02:26:22
	 * 
	 * @param key
	 * @return
	 */
	protected static Object getFromSession(String key) {
		return ServletActionContext.getRequest().getSession().getAttribute(key);
	}

	/**
	 * 从request Attribute中取数据
	 * 
	 * @author zhl
	 * @date 2012-05-08下午04:00:17
	 * 
	 * @param key
	 * @return
	 */
	protected Object getFromRequstAttribute(String key) {
		return ServletActionContext.getRequest().getAttribute(key);
	}

	/**
	 * 从request Parameter中取数据
	 * 
	 * @author zhl
	 * @date 2012-05-08下午09:33:11
	 * 
	 * @param key
	 * @return
	 */
	protected String getFromRequestParameter(String key) {
		return ServletActionContext.getRequest().getParameter(key);
	}
}
